var POLL_FREQUENCY = 5000;
var webpageData = "";

function httpGet(theUrl, callback)
{
    var xmlHttp = null;
    
    xmlHttp = new XMLHttpRequest();
    xmlHttp.open( "GET", theUrl, false );
    xmlHttp.send( null );
    // TODO:  handle network errors
    callback(xmlHttp.responseText);
}

function doPoll()
{
    //httpGet( document.location.pathname + "?checkUpdate" , function(newData)
    httpGet( document.location.pathname, function(newData)
    {
        if (webpageData == "")
        {
            webpageData = newData;
        }
        else
        {
            if (webpageData != newData)
            {
                // need to refresh
                document.location.reload(true);
            }
        }
        setTimeout(doPoll,POLL_FREQUENCY);
    });
}

doPoll();
